package com.neu.niuyuchao.service;

import com.neu.niuyuchao.dao.MgrInfoDaoImpl;
import com.neu.niuyuchao.util.ConvertUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MgrInfoService {
    private MgrInfoDaoImpl mgrInfoDao;
    public MgrInfoService(){
        mgrInfoDao=new MgrInfoDaoImpl();
    }
    public boolean doSave(Map<String,String[]> params,String fileName){
        boolean flag=false;
        try {
            Map<String,String> item=ConvertUtil.convert(params);
            item.put("mgr_img",fileName);
            int row=mgrInfoDao.insert(item);
            if(row>0){
                flag=true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }
    public Map<String,Object> doFindAllDor(){
        Map<String,Object> params=new HashMap<>();
        List<Map<String, Object>> list=null;
        list=mgrInfoDao.findAllDor();
        if(list.size()==1){
           params=list.get(0);
        }
        return params;
    }

    public String getPageNum(int pageCount) {
        String pageNum = "0";
        Map<String, Object> item = new HashMap<>();

        List<Map<String, Object>> list = mgrInfoDao.dorCompare(pageCount);
        if (list.size()>0) {
            item = list.get(0);
            Object p = item.get("a");
            pageNum = String.valueOf(p);
        }

        return pageNum;
    }
   public List<Map<String,Object>> doDorCompare(String pageIndex, int pageNum){
       List<Map<String, Object>> list=new ArrayList<>();
       int a=Integer.parseInt(pageIndex);
       list=mgrInfoDao.findPage(a,pageNum);
       return list;
   }

}